package com.jprocms.module.cms.config;

import com.jpro.framework.datapermission.core.rule.dept.DeptDataPermissionRule;
import com.jpro.framework.datapermission.core.rule.dept.DeptDataPermissionRuleCustomizer;
import com.jprocms.module.cms.dal.dataobject.channel.ChannelDO;
import com.jprocms.module.cms.dal.dataobject.site.SiteDO;
import com.jprocms.module.cms.permission.ChannelPermissionRuleCustomizer;
import com.jprocms.module.cms.permission.ContentPermissionRuleCustomizer;
import com.jprocms.module.cms.permission.SitePermissionRuleCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * cms 模块的数据权限 Configuration
 *
 * @author 泽睿
 */
@Configuration(proxyBeanMethods = false)
public class DataPermissionConfiguration {

    @Bean
    public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() {
        return rule -> {
            // 栏目表 的部门和用户字段
            rule.addDeptColumn(ChannelDO.class, DeptDataPermissionRule.DEPT_COLUMN_NAME);
            rule.addUserColumn(ChannelDO.class, DeptDataPermissionRule.USER_COLUMN_NAME);
        };
    }

    @Bean
    public ChannelPermissionRuleCustomizer channelPermissionRuleCustomizer() {
        return rule -> {
            //栏目表的id 需要鉴定栏目类权限
            rule.addChannelColumn(ChannelDO.class, "id");
        };
    }

    @Bean
    public ContentPermissionRuleCustomizer contentPermissionRuleCustomizer() {
        return rule -> {
            //栏目表的id 需要鉴定栏目类权限
            rule.addChannelColumn(ChannelDO.class, "id");
        };
    }


    @Bean
    public SitePermissionRuleCustomizer sitePermissionRuleCustomizer() {
        return rule -> {
            //站群类
            rule.addSiteColumn(SiteDO.class, "id");
        };
    }

}
